package com.kfm.jdbc.day0403;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class Demo06 {

    public static void main(String[] args) {
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }

        String url = "jdbc:mysql://localhost:3306/kfm_store";
        try {
            Connection connection = DriverManager.getConnection(url, "root", "");
            connection.setAutoCommit(false);

            String query = "INSERT INTO test (id, name) VALUES (?, ?)";
            PreparedStatement preparedStatement = connection.prepareStatement(query);

            preparedStatement.setObject(1, 1);
            preparedStatement.setString(2, "test1");
            preparedStatement.addBatch();

            preparedStatement.setObject(1, 2);
            preparedStatement.setString(2, "test2");
            preparedStatement.addBatch();


            preparedStatement.executeBatch();

            connection.commit();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }

    }
}
